package com.gjzhao.fammll.controller;

import com.gjzhao.fammll.service.MessageService;
import com.gjzhao.fammll.service.OrderService;
import com.gjzhao.fmmall.entity.Orders;
import com.gjzhao.fmmall.vo.RespResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 消息处理Controller
 * @Author: gjzhao
 * @Date Created in 2022-02-19 2:53 下午
 */
@RestController
@CrossOrigin
public class MessageController {


    @Autowired
    private MessageService messageService;
    @Autowired
    private OrderService orderService;


    @GetMapping("message/sendMessage")
    public RespResultVO sendMessage(String message) {

        messageService.sendMessage(message);
        return RespResultVO.success();

    }

    //使用配置方式创建交换机与队列，并进行绑定
    @GetMapping("message/sendMessageByInit")
    public RespResultVO sendMessageByInit(String message) {

        messageService.sendMessageByInitExchangeAndQueue(message);
        return RespResultVO.success();

    }

    //保存订单：RabbitMQ使用json方式传递对象
    @GetMapping("order/saveOrder")
    public RespResultVO saveOrder(Orders order) {

        orderService.saveOrder(order);
        return RespResultVO.success();

    }

    //保存订单：使用rabbitMq实现延时队列的功能
    @GetMapping("order/saveOrderByDeadQueue")
    public RespResultVO saveOrderByDeadQueue(Orders order) {

        orderService.saveOrderByDeadQueue(order);
        return RespResultVO.success();

    }
}
